home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / database / blt2rx_o.zip / SCRIPTS.ZIP / 06MIDK.CMD < prev    next >
OS/2 REXX Batch file  |  1996-08-05  |  21KB  |  479 lines

  1. /* 06 - key mid-level examples for Bullet/REXX */
  2. /* 3-Aug-96
  3.    Calls made in this example:
  4.    - blt_Init()
  5.    - blt_DeleteFileDos()   [to delete test-generated files]
  6.    - blt_CreateData()
  7.    - blt_OpenData()
  8.    - blt_CreateIndex()
  9.    - blt_OpenIndex()
  10.    - blt_AddRecord()
  11.    - blt_BuildKey()
  12.    - blt_LockIndex()
  13.    - blt_StoreKey()
  14.    - blt_UnlockIndex()
  15.    - blt_RelockIndex()
  16.    - blt_xxxKey()           [xxx=First, Equal, Next, Prev, Last]
  17.    - blt_GetRecord()
  18.    - blt_DeleteKey()
  19.    - blt_GetCurrentKey()
  20.    - blt_GetKeyForRecord()
  21.    - blt_CloseIndex()
  22.    - blt_CloseData()
  23.    - blt_Exit()
  24. */
  25.  
  26. /* Typically, each test routine's arg pack (blt_IP., etc.) is set to NOVALUE */
  27. /* so that any unset variables can easily be identified.  In actual use, */
  28. /* this would not be necessary since often arg pack values are already setup */
  29. /* for multiple calls, where blt_?P.variable is already properly set up */
  30.  
  31. /* Doing so, however, means Bullet/REXX checks on variables existing are */
  32. /* effectively bypassed, and typically, missing variables are set to 0 */
  33. /* and used without warning (if a valid value) rather than Bullet/REXX */
  34. /* generating an appropriate syntax error */
  35.  
  36.  say "Example: 06midk.cmd  (recommend output be redirected to a file)"
  37.  
  38.  call RxFuncAdd 'BulletLoadFuncs', 'BREXXI2', 'BulletLoadFuncs'
  39.  call BulletLoadFuncs
  40.  
  41.  /* in case Bullet/REXX is still active, close it out */
  42.  
  43.  rez = blt_Exit()
  44.  
  45.  say
  46.  say "calling blt_Init()"
  47.  blt_IP.=NOVALUE
  48.  blt_IP.JFTsize=5       /* must be 5 */
  49.  rez = blt_Init()       /* init Bullet/REXX */
  50.  say " blt_IP.func is" blt_IP.func
  51.  say " blt_IP.stat is" blt_IP.stat  /* rez same as stat except for xactions */
  52.  if rez = 0 then do
  53.  
  54.     say " blt_IP.versionDOS is" blt_IP.versionDOS
  55.     say " blt_IP.versionOS is" blt_IP.versionOS
  56.     say " blt_IP.versionBullet is" blt_IP.versionBullet
  57.     /* say " blt_IP.exitPtr is" blt_IP.exitPtr */
  58.  
  59.     say
  60.     say "calling blt_DeleteFileDos() x3"
  61.     blt_DFP.=NOVALUE
  62.     blt_DFP.filename = "06MIDK.DBF"
  63.     rez = blt_DeleteFileDos();
  64.     say " blt_DFP.func is" blt_DFP.func
  65.     say " blt_DFP.stat is" blt_DFP.stat "(06MIDK.DBF) [stat=2, file not found, is possible]"
  66.  
  67.     blt_DFP.=NOVALUE
  68.     blt_DFP.filename = "06MIDK.DBT"  /* may use QuerySysVars for memo .EXT */
  69.     rez = blt_DeleteFileDos();
  70.     say " blt_DFP.stat is" blt_DFP.stat "(06MIDK.DBT)"
  71.  
  72.     blt_DFP.=NOVALUE
  73.     blt_DFP.filename = "06MIDK.IX3"
  74.     rez = blt_DeleteFileDos();
  75.     say " blt_DFP.stat is" blt_DFP.stat "(06MIDK.IX3)"
  76.  
  77.     say
  78.     say "calling blt_CreateData()"
  79.     blt_CDP.=NOVALUE
  80.     blt_CDP.filename = "06MIDK.DBF"
  81.     blt_CDP.noFields = 3
  82.     blt_CDP.FD.1.fieldName = "SSN"
  83.     blt_CDP.FD.1.fieldType = "N"
  84.     blt_CDP.FD.1.fieldLen = 9
  85.     blt_CDP.FD.1.fieldDC = 0
  86.     blt_CDP.FD.2.fieldName = "NAME"
  87.     blt_CDP.FD.2.fieldType = "C"
  88.     blt_CDP.FD.2.fieldLen = 10
  89.     blt_CDP.FD.2.fieldDC = 0
  90.     blt_CDP.FD.3.fieldName = "ADDR"
  91.     blt_CDP.FD.3.fieldType = "M"
  92.     blt_CDP.FD.3.fieldLen = 10
  93.     blt_CDP.FD.3.fieldDC = 0
  94.     blt_CDP.fileID = 139        /* memo, too  (139 is 0x8B [hex]) */
  95.     rez = blt_CreateData()      /* create data files: DBF and DBT */
  96.     say " blt_CDP.func is" blt_CDP.func
  97.     say " blt_CDP.stat is" blt_CDP.stat
  98.  
  99.     /* since region locking of data file was demo'ed in 05midm.cmd, this */
  100.     /* locks the file at open time for the data file, and demonstrates */
  101.     /* region locking (could be called on demand locking) for the index */
  102.     /* -- for quick and dirty and simple use, file open locks are okay */
  103.     /* -- but for multi-user environments, in complex programs, region */
  104.     /* -- lock calls (blt_Lock/blt_Unlock) are probably much better since */
  105.     /* -- the file (or region) can be locked on demand, without having */
  106.     /* -- to close/re-open the file in another share mode as would be */
  107.     /* -- needed if region locks weren't available */
  108.  
  109.     if rez = 0 then do
  110.        say
  111.        say "calling blt_OpenData()"
  112.        blt_OP.=NOVALUE
  113.        blt_OP.filename = blt_CDP.filename
  114.        blt_OP.asMode = 18       /* 18 is 0x0012 [hex] DENYRW, R/W */
  115.        rez = blt_OpenData()     /* data is locked at file level (demo purpose) */
  116.        say " blt_OP.func is" blt_OP.func
  117.        say " blt_OP.stat is" blt_OP.stat
  118.  
  119.        /* must have data DBF open before creating index for it */
  120.        /* and good idea to have at least a shared lock on it while */
  121.        /* index file for it is being created */
  122.  
  123.        dataID = 0       /* since two opens are done, cannot keep both handles */
  124.        indexID = 0      /* in the same blt_OP.handle var, so do this */
  125.  
  126.        if rez = 0 then do
  127.           dataID = blt_OP.handle
  128.           say " blt_OP.handle is" dataID
  129.           say
  130.           say "calling blt_CreateIndex()"
  131.           blt_CIP.=NOVALUE
  132.           blt_CIP.filename = "06MIDK.IX3"
  133.           blt_CIP.keyExp = "SSN"        /* index is on entire SSN field */
  134.           blt_CIP.xbLink = dataID       /* blt_OP.handle from DBF open above */
  135.           blt_CIP.sortFunction = 1      /* ASCII sort, dups -not- allowed */
  136.           blt_CIP.codePage = 0
  137.           blt_CIP.countryCode = 0
  138.           blt_CIP.collateTable = ""     /* 0-len string for default, else 256-char table of weights */
  139.           blt_CIP.nodeSize = 512
  140.           rez = blt_CreateIndex()
  141.           say " blt_CIP.func is" blt_CIP.func
  142.           say " blt_CIP.stat is" blt_CIP.stat
  143.  
  144.           if rez = 0 then do
  145.              say
  146.              say "calling blt_OpenIndex()"
  147.              blt_OP.=NOVALUE
  148.              blt_OP.filename = blt_CIP.filename
  149.              blt_OP.asMode = 66       /* 66 is 0x0042 [hex] DENYNONE, R/W */
  150.  
  151.              /* index open requires blt_OP.xbLink set to DBF handle */
  152.              /* whereas .xbLink is not used in a data open */
  153.  
  154.              blt_OP.xbLink = dataID
  155.              rez = blt_Openindex()
  156.              say " blt_OP.func is" blt_OP.func
  157.              say " blt_OP.stat is" blt_OP.stat
  158.  
  159.              if rez = 0 then do
  160.                 indexID = blt_OP.handle
  161.                 say " blt_OP.handle is" indexID
  162.  
  163.                 say
  164.                 say "calling blt_LockIndex()  [to exclusive lock, read-write]"
  165.                 blt_LP.=NOVALUE
  166.                 blt_LP.handle = indexID
  167.                 blt_LP.xlMode = 0     /* 0=exclusive lock; 1=shared lock */
  168.                 rez = blt_LockIndex()
  169.                 say " blt_LP.func is" blt_LP.func
  170.                 say " blt_LP.stat is" blt_LP.stat
  171.                 if rez = 0 then do
  172.  
  173.                    say
  174.                    say "calling blt_AddRecord(),_BuildKey(),_StoreKey(), 100 times"
  175.                    blt_AP.=NOVALUE
  176.  
  177.                    /* generates SSN numbers from 465100001 to 465100100 */
  178.                    /* leading delete tag field (space) */
  179.                    /* NAME field just filled in with ... nothing important */
  180.                    /* this loop writes 100 records to disk */
  181.                    /* raw record is SSN(9), NAME(10), ADDR(10/memo number) */
  182.                    /* with the memo number in ADDR left empty */
  183.                    /* -- also builds key for each and stores it to index file */
  184.                    /* -- duplicates not automatically handled by mid-level calls */
  185.                    /* note that, as in all calls, .func is returned only if the */
  186.                    /* final call to Bullet/REXX is actually made; any errors */
  187.                    /* occuring prior to that call will have .func left as it */
  188.                    /* was when last set -- */
  189.  
  190.                    /* this 3-call procedure is typically handled by */
  191.                    /*                                               */
  192.                    /*           blt_Insert()                        */
  193.                    /*                                               */
  194.                    /* which performs this task much better than can */
  195.                    /* be done by doing it this way                  */
  196.  
  197.                    f1 = 0
  198.                    f2 = 0
  199.                    f3 = 0
  200.                    do record = 100001 to 100100 until rez <> 0
  201.                       blt_AP.recData = " 465"record"name-nadaZ          "
  202.                       step = 1
  203.                       blt_AP.handle = dataID
  204.                       rez = blt_AddRecord()  /* returns blt_AP.recNo */
  205.                       if f1 = 0 then f1 = blt_AP.func
  206.                       if rez = 0 then do
  207.  
  208.                          step = 2
  209.                          blt_AP.handle = indexID
  210.                          rez = blt_BuildKey()  /* blt_AP. values already set */
  211.                          if f2 = 0 then f2 = blt_AP.func
  212.                          if rez = 0 then do
  213.  
  214.                             step = 3
  215.                             rez = blt_StoreKey() /* likewise, already set up */
  216.                             if f3 = 0 then f3 = blt_AP.func
  217.                          end
  218.                       end
  219.                    end
  220.                    say " blt_AddRecord() blt_AP.func is" f1
  221.                    say " blt_BuildKey()  blt_AP.func is" f2
  222.                    say " blt_StoreKey()  blt_AP.func is" f3
  223.                    say " Last blt_AP.stat is" blt_AP.stat
  224.                    if rez = 0 then do
  225.  
  226.                       /* for demo purpose, this physically removes last */
  227.                       /* physical data record and its key, added last */
  228.  
  229.                       say
  230.                       say "calling blt_DebumpRecord()"
  231.                       blt_AP.handle = dataID
  232.                       rez = blt_DebumpRecord()  /* again, already set up */
  233.                       say " blt_AP.func is" blt_AP.func
  234.                       say " blt_AP.stat is" blt_AP.stat
  235.                       if rez = 0 then do
  236.  
  237.                          say
  238.                          say "calling blt_DeleteKey()"
  239.                          blt_AP.handle = indexID
  240.                          rez = blt_DeleteKey()    /* delete key in blt_AP.keyData */
  241.                          say " blt_AP.func is" blt_AP.func
  242.                          say " blt_AP.stat is" blt_AP.stat
  243.                          if rez = 0 then do
  244.  
  245.                             /* done writing to file, can release lock */
  246.                             /* actually, may have been better to unlock/lock */
  247.                             /* once per call -- in any case, instead of */
  248.                             /* releasing, from demo purpose, relock index */
  249.  
  250.                             say
  251.                             say "calling blt_RelockIndex()  [to shared lock, read-only]"
  252.                             blt_LP.=NOVALUE
  253.                             blt_LP.handle = indexID
  254.                             blt_LP.xlMode = 1     /* 0=exclusive lock; 1=shared lock */
  255.                             rez = blt_RelockIndex()
  256.                             say " blt_LP.func is" blt_LP.func
  257.                             say " blt_LP.stat is" blt_LP.stat
  258.                             if rez = 0 then do
  259.  
  260.                                /* quick exercise of key-only access */
  261.                                /* returned is the record number of the key */
  262.                                /* accessed, and from that, its record can */
  263.                                /* be gotten with a call to blt_GetRecord() */
  264.                                /* as shown in the blt_PrevKey() example */
  265.  
  266.                                say
  267.                                say "calling blt_FirstKey()"
  268.                                rez = blt_FirstKey()
  269.                                say " blt_AP.func is" blt_AP.func
  270.                                say " blt_AP.stat is" blt_AP.stat
  271.                                say " blt_AP.keyData is '"blt_AP.keyData"' recNo:" blt_AP.recNo
  272.                                if rez = 0 then do
  273.  
  274.                                   say
  275.                                   say "calling blt_EqualKey()  [using FirstKey as search key]"
  276.                                   rez = blt_EqualKey()
  277.                                   say " blt_AP.func is" blt_AP.func
  278.                                   say " blt_AP.stat is" blt_AP.stat
  279.                                   say " blt_AP.keyData is '"blt_AP.keyData"' recNo:" blt_AP.recNo
  280.                                   if rez = 0 then do
  281.  
  282.                                      say
  283.                                      say "calling blt_NextKey()"
  284.                                      rez = blt_NextKey()
  285.                                      say " blt_AP.func is" blt_AP.func
  286.                                      say " blt_AP.stat is" blt_AP.stat
  287.                                      say " blt_AP.keyData is '"blt_AP.keyData"' recNo:" blt_AP.recNo
  288.                                      if rez = 0 then do
  289.  
  290.                                         say
  291.                                         say "calling blt_LastKey()"
  292.                                         rez = blt_LastKey()
  293.                                         say " blt_AP.func is" blt_AP.func
  294.                                         say " blt_AP.stat is" blt_AP.stat
  295.                                         say " blt_AP.keyData is '"blt_AP.keyData"' recNo:" blt_AP.recNo
  296.                                         if rez = 0 then do
  297.  
  298.                                            say
  299.                                            say "calling blt_PrevKey()"
  300.                                            rez = blt_PrevKey()
  301.                                            say " blt_AP.func is" blt_AP.func
  302.                                            say " blt_AP.stat is" blt_AP.stat
  303.                                            say " blt_AP.keyData is '"blt_AP.keyData"' recNo:" blt_AP.recNo
  304.                                            if rez = 0 then do
  305.  
  306.                                               say
  307.                                               say "calling blt_GetRecord() for that key search"
  308.                                               blt_AP.handle = dataID
  309.                                               rez = blt_GetRecord()
  310.                                               say " blt_AP.func is" blt_AP.func
  311.                                               say " blt_AP.stat is" blt_AP.stat
  312.                                               say " blt_AP.recData is '"blt_AP.recData"'"
  313.                                               if rez = 0 then do
  314.  
  315.                                                  say
  316.                                                  say "calling blt_GetCurrentKey()"
  317.                                                  blt_AP.keyData = ""  /* just to verify return */
  318.                                                  blt_AP.handle = indexID
  319.                                                  rez = blt_GetCurrentKey()
  320.                                                  say " blt_AP.func is" blt_AP.func
  321.                                                  say " blt_AP.stat is" blt_AP.stat
  322.                                                  say " blt_AP.recNo is" blt_AP.recNo
  323.                                                  say " blt_AP.keyData is '"blt_AP.keyData"'"
  324.                                                  if rez = 0 then do
  325.  
  326.                                                     say
  327.                                                     say "calling blt_GetKeyForRecord() with '"blt_AP.recData"' and rec#" blt_AP.recNo
  328.  
  329.                                                     blt_AP.keyData = "" /* again, to verify return */
  330.  
  331.                                                     /* this routine finds the exact key for the recData/recNo pair */
  332.                                                     /* typically an extraneous routine, but may be useful at times */
  333.  
  334.                                                     rez = blt_GetKeyForRecord()
  335.                                                     say " blt_AP.func is" blt_AP.func
  336.                                                     say " blt_AP.stat is" blt_AP.stat
  337.                                                     say " blt_AP.keyData is '"blt_AP.keyData"'"
  338.                                                     if rez = 0 then do
  339.  
  340.                                                        say
  341.                                                        say "Excellent!  All calls went as planned"
  342.                                                     end
  343.                                                     else do
  344.                                                        say "* ERROR * blt_GetKeyForRecord()"
  345.                                                     end
  346.  
  347.                                                  end
  348.                                                  else do
  349.                                                     say "* ERROR * blt_GetCurrentKey()"
  350.                                                  end
  351.  
  352.                                               end
  353.                                               else do
  354.                                                  say "* ERROR * blt_GetRecord()"
  355.                                               end
  356.  
  357.                                            end
  358.                                            else do
  359.                                               say "* ERROR * blt_PrevKey()"
  360.                                            end
  361.  
  362.                                         end
  363.                                         else do
  364.                                            say "* ERROR * blt_LastKey()"
  365.                                         end
  366.  
  367.                                      end
  368.                                      else do
  369.                                         say "* ERROR * blt_NextKey()"
  370.                                      end
  371.  
  372.                                   end
  373.                                   else do
  374.                                      say "* ERROR * blt_EqualKey()"
  375.                                   end
  376.  
  377.                                end
  378.                                else do
  379.                                   say "* ERROR * blt_FirstKey()"
  380.                                end
  381.  
  382.                             end
  383.                             else do
  384.                                say "* ERROR * blt_RelockIndex()"
  385.                             end
  386.  
  387.                          end
  388.                          else do
  389.                             say "* ERROR * blt_DeleteKey()"
  390.                          end
  391.  
  392.                       end
  393.                       else do
  394.                          say "* ERROR * blt_DebumpRecord()"
  395.                       end
  396.  
  397.                    end
  398.                    else do
  399.                       if step = 1 then say "* ERROR * blt_AddRecord()"
  400.                       if step = 2 then say "* ERROR * blt_BuildKey()"
  401.                       if step = 3 then say "* ERROR * blt_StoreKey()"
  402.                       say "  at record" record
  403.                    end
  404.  
  405.                    /* typically would not wait this long (i.e., the end) */
  406.                    /* to unlock, but this is only a demo */
  407.  
  408.                    say
  409.                    say "calling blt_UnLockIndex()"
  410.                    blt_LP.=NOVALUE
  411.                    blt_LP.handle = indexID
  412.                    rez = blt_UnlockIndex()
  413.                    say " blt_LP.func is" blt_LP.func
  414.                    say " blt_LP.stat is" blt_LP.stat
  415.  
  416.                 end
  417.                 else do
  418.                    say "* ERROR * blt_LockIndex()"
  419.                 end
  420.  
  421.                 /* if open, it's a good idea to close it (blt_Exit() will if not) */
  422.  
  423.                 blt_HP.=NOVALUE
  424.                 blt_HP.handle = indexID
  425.                 say
  426.                 say "calling blt_CloseIndex()"
  427.                 rez = blt_CloseIndex()
  428.                 say " blt_HP.func is" blt_HP.func
  429.                 say " blt_HP.stat is" blt_HP.stat
  430.  
  431.              end
  432.              else do
  433.                 say "* ERROR * blt_OpenIndexHeader()"
  434.              end
  435.  
  436.           end
  437.           else do
  438.              say "* ERROR * blt_CreateIndex()"
  439.           end
  440.  
  441.  
  442.           /* if open, it's a good idea to close it (blt_Exit() will if not) */
  443.           /* data file was opened for exclusive access, so not locked */
  444.  
  445.           blt_HP.=NOVALUE
  446.           blt_HP.handle = dataID
  447.           say
  448.           say "calling blt_CloseData()"
  449.           rez = blt_CloseData()
  450.           say " blt_HP.func is" blt_HP.func
  451.           say " blt_HP.stat is" blt_HP.stat
  452.  
  453.        end
  454.        else do
  455.           say "* ERROR * blt_OpenData()"
  456.        end
  457.  
  458.     end
  459.     else do
  460.        say
  461.        say "* ERROR * blt_CreateData()"
  462.     end
  463.  
  464.     say
  465.     say "calling blt_Exit()"
  466.     blt_EP.=NOVALUE
  467.     rez = blt_Exit()
  468.     say " blt_EP.func is" blt_EP.func
  469.     say " blt_EP.stat is" blt_EP.stat
  470.     say " blt_EP.rxAllocsLeft is" blt_EP.rxAllocsLeft
  471.  end
  472.  else do
  473.     say
  474.     say "* ERROR * blt_Init()"
  475.  end
  476.  
  477.  call BulletDropFuncs
  478.  exit 0
  479.